package com.xiegang.serviceverificationcode.controller;

import com.xiegang.internalcommon.dto.ResponseResult;
import com.xiegang.internalcommon.response.NumberCodeResponse;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xieGang
 * @description
 * @date 2023/3/1 16:18
 **/
@RestController
public class NumberCodeController {

    @GetMapping("/numberCode/{size}")
    public ResponseResult numberCode(@PathVariable("size") int size){

        //生成验证码
        //获取随机小数[0,1) 大于等于0 小于1    *9避免第一个数为0  +1避免随机数为0.0000001都是一样的     *10的size-1次方
        double mathRandom = (Math.random()*9+1)*Math.pow(10,size-1);
        int resultInt = (int) mathRandom;

        NumberCodeResponse numberCodeResponse = new NumberCodeResponse();
        numberCodeResponse.setNumberCode(resultInt);
        return ResponseResult.success(numberCodeResponse);
    }

}
